{extends 'base/site2.html'}
{block name="page_header"}{include file="common/header.html" inline}{/block}
{block name="page_nav"}{include file="common/slide-nav.html" inline}{/block}
{block name="page_styles"}
    <link rel="stylesheet" type="text/css" href="/css/mediation/caseimport/index.css" />
    <style>
        :not(.input-group)>.bootstrap-select.form-control:not([class*=col-]){
            width: 100%;
        }
        button {
          outline: none!important;
        }

        .btn-on{
            width: 60px;
            height: 25px;
            margin: 0 3px;
            border-radius: 25px;
            font-size: 14px;
        }
        .btn-on{
            cursor: pointer;
            position: relative;
            border: 1px solid white;
            background-color: #4893f8;
        }
        .btn-on-circle{
            position: absolute;
            width: 15px;
            height: 15px;
            top: 5px;
            left: 5px;
            background-color: rgb(255, 255, 255);
            border-radius: 50%;
            box-shadow: 0 0 10px white;
            transition: all .5s;
        }
        .btn-on-text{
            position: absolute;
            right: 10px;
            line-height: 25px;
            color: white;
            transition: all .5s;
        }
    </style>
{/block}
{block name="page_section"}
<div class="sessionPage clearfix">
    <div class="clearfix page-header">
      <div class="left">
        <span class="line"></span>
        <strong class="tit">导入记录</strong>
      </div>
      <div class="">
        <button type="button" data-target="#modal_upload_case" data-toggle="modal" class="btn btn-info textright btn-xs">案件导入</button>
      </div>
    </div>
    <form method="get" action="" role="validform" enctype="multipart/form-data" class="small-style">
      <div class="form_row">
        <div class="form-group col-lg-3 ui-select">
            <label for="exampleInputName2"  class="col-sm-4 control-label">调解部门:</label>
            <div class="col-sm-7">
                <select class="form-control selectpicker" name="mediationOrganId">
                    <option class="u144_input_option" {if $query.mediationOrganId == 0}selected="selected"{/if} value="0">全部</option>
                    {foreach from=$mediationOrgan  item=info}
                        <option class="u144_input_option" {if !empty($query.mediationOrganId) &&  $info.id== $query.mediationOrganId}selected="selected"{/if} value="{$info.id}">{$info.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="form-group col-lg-3 ui-select">
            <label for="exampleInputName2"  class="col-sm-4 control-label">资产方:</label>
            <div class="col-sm-7">
                <select class="form-control selectpicker"  title="请选择" name="assetsId" id="assetsId">
                    {foreach from=$assets  item=info}
                        <option class="u144_input_option" {if !empty($query.assetsId) &&  $info.id== $query.assetsId}selected="selected"{/if} value="{$info.id}">{$info.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="form-group col-lg-3 ui-select">
            <label for="exampleInputName2" class="col-sm-4 control-label">导入批次ID:</label>
            <div class="col-sm-7">
                <input type="text" class="form-control noempty col-sm-4" value="{$query.id}" name="id" placeholder="请输入~">
            </div>
        </div>
          <div class="form-group col-lg-3 ui-select">
              <label for="exampleInputName2" class="col-sm-4 control-label">批次名称:</label>
              <div class="col-sm-7">
                  <input type="text" class="form-control noempty col-sm-4" value="{$query.batchName}" name="batchName" placeholder="请输入~">
              </div>
          </div>
      </div>
      <div class="form_row">
          <div class="form-group col-lg-3 ui-select">
              <label class="col-sm-3 control-label text-nowrap">导入时间:</label>
              <div class="col-sm-7">
                  <input data-ele="date" data-type="daterange" name="add_begin_end" class="form-control" placeholder="请选择" value="{if !empty($smarty.get.add_begin_end)}{$smarty.get.add_begin_end}{/if}" autocomplete="off"/>
                  {* <input data-ele="date" data-type="date" name="add_begin_end" class="form-control" placeholder="请选择" value="{if !empty($query['add_begin_end'])}{$query.add_begin_end}{/if}" autocomplete="off"/>*}
              </div>
          </div>
        <div class="form-group col-lg-3 ui-select">
            <label for="exampleInputName2" class="col-sm-4 control-label">文件识别状态:</label>
            <div class="col-sm-7">
                <select class="form-control selectpicker" name="status" >
                    <option class="u144_input_option" {if $query.status eq 0}selected="selected"{/if} value="0">全部
                    </option>
                    <option class="u144_input_option" {if $query.status eq 1}selected="selected"{/if} value="1">识别中
                    </option>
                    <option class="u144_input_option" {if $query.status eq 2}selected="selected"{/if} value="2">识别成功
                    </option>
                    <option class="u144_input_option" {if $query.status eq 3}selected="selected"{/if} value="3">识别失败
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group col-lg-3 ui-select">
            <label for="exampleInputName2" class="col-sm-4 control-label">导入状态:</label>
            <div class="col-sm-7">
                <select class="form-control selectpicker" name="submitStatus">
                    <option class="u144_input_option" {if $query.submitStatus==0}selected="selected"{/if}
                            value="0">全部
                    </option>
                    <option class="u144_input_option" {if $query.submitStatus==1}selected="selected"{/if}
                            value="1">未导入
                    </option>
                    <option class="u144_input_option" {if $query.submitStatus==2}selected="selected"{/if}
                            value="2">导入中
                    </option>
                    <option class="u144_input_option" {if $query.submitStatus==3}selected="selected"{/if}
                            value="3">导入完成
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group col-lg-3 ui-select">
          <div class="col-lg-5">
            <button class="btn btn-primary col-lg-8 shousuoBtn "><span class="nav-icon glyphicon glyphicon-search" aria-hidden="true" style="margin-right: 2px"></span>查询</button>
          </div>
          <div class="col-lg-5">
            <a type="button" href="/caseimport" class="btn btn-default col-lg-8 "><span class="nav-icon glyphicon glyphicon-refresh" aria-hidden="true" style="margin-right: 2px"></span>重置</a>
          </div>
        </div>
      </div>
    </form>
    <div style="
      width: 95%;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      overflow-x: scroll;">
      <table class="table table-striped table-bordered table-hover text-nowrap" id="tab">
        <thead>
        <tr>
            <th>批次ID</th>
            <th>批次名称</th>
            <th>调解部门</th>
            <th>资产方</th>
            <th>纠纷类型</th>
            <th>案件类型</th>
            <th>债权类型</th>
            <th>导入时间</th>
            <th>识别数量(成功/失败)</th>
            <th>导入数量(成功/失败)</th>
            <th>审核驳回数量</th>
            <th>审核通过数量</th>
            <th>审核通过欠款本金</th>
            <th>审核通过欠款总额</th>
            <th>识别状态</th>
            <th>导入状态</th>
            <th>导入人员</th>
            <th>闪信开关</th>
            <th class="fix-ele">操作</th>
        </thead>
    <tbody>
    {if $arrList}
        {foreach from=$arrList item=item name=foo}
            <tr>
                <td>{$item.id}</td>
                <td>  <a style="color:#007bff" href="/caseimport/recorddetail?recordId={$item.id}">{$item.batchName}</a></td>

                <td>
                    {$mediationOrgan[$item.mediationOrganId]['name']}
                </td>
                <td>
                    {$assets[$item.assetsId]['name']}
                </td>
                <td>
                    {$disputeType[$item.disputeType]}
                </td>
                <td><p
                        {if $item.caseType == 2}
                        style="color: #77c87a;background-color:#ecf5ec;padding: 3px 4px;border-radius:5px"
                        {elseif $item.caseType == 3}
                        style="color: #FF5460;background-color:#fff4f9;padding: 3px 4px;border-radius:5px"
                        {else}
                        style="color: #03A9F4;background-color:#e2eef6;padding: 3px 4px;border-radius:5px"
                        {/if}
                    >{$caseType[$item.caseType]}</p></td>
                <td>
                    {if $item.assetType==1}自有债权{else}转让债权{/if}
                </td>
                <td>{$item['addTime']|date_format:"%Y-%m-%d %H:%M:%S"}</td>

                <td style="text-align: center;">{$item.sucessNum} / {$item.errorNum}</td>
                <td style="text-align: center;">{if $item.submitStatus!=1}{$item.submitSuccessNum} / {$item.submitErrorNum}{else}--{/if}</td>
                <td style="text-align: center;">{if $item.statistic==0 && $item.rejectedNum==0}--{else}{$item.rejectedNum}{/if}</td>
                <td style="text-align: center;">{if $item.statistic==0 && $item.approvedNum==0}--{else}{$item.approvedNum}{/if}</td>
                <td style="text-align: center;">{if $item.statistic==0 && $item.approvedDebtAmount==0}--{else}{number_format($item.approvedDebtAmount,2)}{/if}</td>
                <td style="text-align: center;">{if $item.statistic==0 && $item.approvedDebtTotal==0}--{else}{number_format($item.approvedDebtTotal,2)}{/if}</td>
                <td>{if $item.status==0}未识别{elseif $item.status==1}识别中 {elseif $item.status==2}识别完成{elseif $item.status==3}识别失败 {/if}</td>
                <td>{if $item.submitStatus==1}未导入{elseif $item.submitStatus==2}导入中 {elseif $item.submitStatus==3}导入完成 {/if}</td>
                <td>{$item.uploadName}</td>
                <td>
                    {if $item.isFlashsms == 1}
                        <p class="btn-on btnon " data-id="{$item.id}" data-type=0>
                            <!-- 圆点 -->
                            <span class="btn-on-circle"></span>
                            <!-- 文字 -->
                            <span class="btn-on-text">开</span>
                        </p>
                    {else}
                        <p class="btn-on btnon" data-id="{$item.id}" data-type=1 style= "background-color: #ccc;">
                            <!-- 圆点 -->
                            <span class="btn-on-circle" style="left: 40px;background-color: #888;box-shadow: 0 0 10px #888;"></span>
                            <!-- 文字 -->
                            <span class="btn-on-text"style="right: 30px;color: #888;">关</span>
                        </p>
                    {/if}
                </td>
                <td class="fix-ele">
                    <a href="/caseimport/recorddetail?recordId={$item.id}">批次详情</a> |
                    {*不可导入：1.三要素检测率低于40% 2.识别成功数为0 3.导入中或导入完成*}
                    {if $item.sucessNum==0 || $item.submitStatus > 1}
                        <font color="#8c8c8c">确定导入</font>
                    {else}
                        <a data-id="{$item.id}" data-toggle="modal" data-target="#case_submit" data-num = "{$item.sucessNum}" id='import_submit'>确定导入</a>
                    {/if} |
                    {if $item.submitSuccessNum==0 || $item.submitStatus ==1}
                        <a data-type="1" data-toggle="modal" data-id="{$item.id}" data-target="#confirm"  id='import_delete'>删除</a>
                    {else}
                        <font color="#8c8c8c">删除</font>
                    {/if}
                </td>
            </tr>
        {/foreach}
    {/if}
    </tbody>
    </table>
    </div>
    <div class="clearfix pad-no text-nowrap" style="margin-top: 20px;">
        {include file="base/pagenav.html"  action="/caseimport/index" pagenum=$curPageNum inline}
        <select class="form-control" id="paglimit" style="float:right;margin:0 10px;width: auto;margin-top: -5px;">
            <option value="limit=10" {if $query.limit==10}selected="selected"{/if}>10条/页</option>
            <option value="limit=20" {if $query.limit==20}selected="selected"{/if}>20条/页</option>
            <option value="limit=50" {if $query.limit==50}selected="selected"{/if}>50条/页</option>
            <option value="limit=100" {if $query.limit==100}selected="selected"{/if}>100条/页</option>
        </select>
        <span style="float:right;">共 {$totalnum} 条</span>
    </div>
</div>

    {* 二次确认 *}
    <div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-labelledby="confirmLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <form  class="form-inline">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="confirmLabel">操作提示</h4>
                    </div>
                    <div class="modal-body">
                        <span class="dialog-tips">您要选择 <b>删除批次</b> 吗？</span>
                        <input type="hidden" value=""  id="deleteRecordId">

                    </div>
                    <div class="modal-footer">
                        <button type="button" id="confirmdel"  class="btn btn-primary">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="modal fade" id="modal_upload_case" tabindex="-1" role="dialog" aria-labelledby="confirmLabel">
        <div class="modal-dialog modal-dialog-centered" role="document" style="background:#FFF;">
            <div class="">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">案件导入</h4>
                    </div>
                    <div style="color: red;padding-left: 5%;margin-top: 10px">
                        <span style="color: red;">注：请勿删除或调整模板列顺序，T后可任意加列</span>
                    </div>
                    <form  class="form-inline" id="importCase_form">
                        <div class="clearfix modal-body">
                            <div class="form_dialog form-group col-sm-12" >
                                <label for="exampleInputName2"  class="col-sm-3 control-label">批次名称:</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control noempty" style="width: 100%" value="{$batchName}" name="batchName" >
                                </div>
                            </div>
                            <div class="form_dialog form-group col-sm-12"  style="margin-top:15px">
                                <label for="exampleInputName2"  class="col-sm-3 control-label">资产方:</label>
                                <div class="col-sm-7">
                                    <select class="form-control selectpicker" name="assetsId" title="请选择">
                                       {foreach from=$assets item=item key=key}
                                            <option class="u144_input_option" value="{$item.id}">{$item.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form_dialog form-group col-sm-12" style="margin-top:15px">
                                <label for="exampleInputName2"  class="col-sm-3 control-label">纠纷类型:</label>
                                <div class="col-sm-7">
                                    <select class="form-control selectpicker" name="disputeType" >
                                        {foreach from=$disputeType  key=key  item=info}
                                        <option class="u144_input_option" value="{$key}">{$info}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form_dialog form-group col-sm-12" style="margin-top:15px">
                                <label for="exampleInputName2"  class="col-sm-3 control-label">案件类型:</label>
                                <div class="col-sm-7">
                                    <select class="form-control selectpicker" name="caseType">
                                        {foreach from=$caseType  key=key  item=info}
                                        <option class="u144_input_option" value="{$key}">{$info}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form_dialog form-group col-sm-12" style="margin-top:15px">
                                <label for="exampleInputName2"  class="col-sm-3 control-label">债权类型:</label>
                                <div class="col-sm-7">
                                    <select class="form-control selectpicker" name="assetType">
                                        <option class="u144_input_option" value="1">自有债权</option>
                                        <option class="u144_input_option" value="2">转让债权</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form_dialog form-group col-sm-12 ui-select" style="margin-top:15px;">
                                <label for="exampleInputName2"  class="col-sm-3 control-label">导入文件:</label>
                                <!-- submit                   -->
                                <div style="color:#93b6e7;display: flex;flex-direction: column;align-items: center;margin: 20px 0;position: relative;">
                                    <i class="glyphicon glyphicon-file" style="font-size: 35px;"></i>
                                    <span>上传文档</span>
                                    <input type="file" class="uploadFile" id="upfile" style="opacity: 0;position: absolute;left: 0;top: 0;right: 0;bottom: 0;cursor: pointer;">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
              <div class="modal-footer">
                  <a type="button" href="/caseimport/downTemplate" style="float: left;" class="btn btn-default left downTemplate">下载模板</a>
                  <button type="button" id="importCaseSubmit" class="btn btn-primary">确定</button>
                  <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
              </div>
          </div>
      </div>
  </div>
  <div class="modal fade" id="case_submit" tabindex="-1" role="dialog" aria-labelledby="refusal_modal" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-content">

              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="exampleModalLabel">案件确定导入</h4>
              </div>
              <div class="modal-body" align="center" >
                      <p> 本次导入共计:<span id="chean_num"></span>宗案件!<p>
                      <p><font color="red">该接口为批量异步操作,请稍后再查看记录状态变化,请耐心等待!</font></p>
                      <input type="hidden" value="" class="recordId" id="recordId">
              </div>
              <div class="modal-footer" style="text-align: center;">
                  <button type="button" class="btn btn-default" id="fpclosebtn" data-dismiss="modal">取消</button>
                  <button type="button" class="btn btn-primary distribution">确定</button>
              </div>


          </div>
      </div>
  </div>

{/block}
{block name="page_scripts"}
<script type="text/javascript" src="/js/mediation/caseimport/index.min.js" init="mediation/caseimport/index"></script>
    <!-- <script type="text/javascript" src="/js/mediation/caseimport/index.min.js" init="mediation/caseimport/index"></script> -->
<script type="text/javascript">
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if(r!=null)return  unescape(r[2]); return null;
    }
    $('body')
        .on('click','.btnon', function(){
            type = $(this).attr("data-type")
            id = $(this).attr("data-id")
            var circle = $(this).find(".btn-on-circle");
            var text = $(this).find(".btn-on-text");
            if(type == 1){
                $(this).removeAttr("style");
                circle.removeAttr("style");
                text.removeAttr("style");
                text.text('开');
                $(this).attr("data-type",  0); // 修改状态
            } else {
                $(this).attr("style","background-color: #ccc;")
                circle.attr("style","left: 40px;background-color: #888;box-shadow: 0 0 10px #888;");
                text.attr("style","right: 30px;color: #888;");
                text.text('关');
                $(this).attr("data-type",  1); // 修改状态
            }
            $.ajax({
                url:"/caseimport/isFlashsms",
                method: "post",
                data: {
                    id: id,
                    flashtype: type
                },
                success:function(res){
                    if(res.code==200){
                        toastr.success(res.message);
                    }else{
                        toastr.error(res.message);
                    }
                }
            })

        })
        .on('change','#paglimit', function(){

            var mediationOrganId = GetQueryString('mediationOrganId');
            var paglimit = GetQueryString('limit');
            var val =  $(this).val();

            if(!mediationOrganId){
                if(!paglimit){
                    window.location = window.location.href+'?'+val;
                } else{
                    window.location = window.location.href.replace('limit='+paglimit,val);
                }
            }else{
                if(!paglimit){
                    window.location = window.location.href+'&'+val;
                } else{
                    window.location = window.location.href.replace('limit='+paglimit,val);
                }
            }
        })

</script>

{/block}
